# 作者：SP
# 开发时间：2023/12/30 10:48
class Car:
    "一次模拟汽车的尝试"
    def __init__(self,make,model,year):
        self.make = make
        self.model = model
        self.year = year
        self.odometer_reading = 0
    def get_deacriptive_name(self):
        long_name = f"{self.year} {self.make} {self.model}"
        return long_name.title()
    def read_odometer(self,mileage):
        print(f'This car has {self.odometer_reading} malis on it')
    def update_odometer(self,mileage):
        if mileage >= self.odometer_reading:
            self.odometer_reading = mileage
        else:
            print("You can't roll back an odometer")
    def increment_odometer(self,miles):
        self.odometer_reading += miles
class ElectricCar(Car):
    "电动汽车的独特之处"
    def __init__(self,make,model,year):
        "初始化父类的属性"
        "给子类定义自已特有的属性和方法"
        self.battery_size = 75
        super().__init__(make,model,year)
        "继承父类的属性和方法"
        "将实例作为属性的写法,此处Battery作为实例赋给属性self.battery"
        self.battery = Battery()                #将实例battery用作electriccar的属性
    def fill_gas_tank(self):
        "电动汽车没有油箱,重写方法吗？？？"
        print('this cat dosent need a gas tank' )
class Battery:
    "一次模拟电动汽车电瓶的尝试"
    def __init__(self,battery_size=75):
        self.battery_size = battery_size
    def describe_battery(self):
        "打印一条描述电瓶容量的消息"
        print(f'This is car {self.battery_size}')
    def get_range(self):
        "打印一条消息，指出电瓶的续航公里"
        if self.battery_size == 75:
            range = 260
        elif self.battery_size == 100:
            range = 315
        print(f"this car can run {range} miles on a full charge")
my_tesla = ElectricCar('tesla','model s',2019)
print(my_tesla.get_deacriptive_name())
"""注意此处将实例作为类属性时调用方法的变化"""
my_tesla.battery.battery_size=100
my_tesla.battery.describe_battery()
my_tesla.battery.get_range()